package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_CAR_MODELS)
public class GetCarModels extends JTAsyGet<GetCarModels.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String brandId ;

    public String seriesId;

    public GetCarModels(String brandId,String seriesId,AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.brandId = brandId;

        this.seriesId = seriesId;
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray dMlist = body.optJSONArray("displacementList");

        JSONArray tMlist = body.optJSONArray("transmissionList");

        JSONArray cMlist = body.optJSONArray("carTypeList");

        MList mDMList1 = new MList();

        mDMList1.ID = "A";

        mDMList1.NAME = "全部排量";

        MList mTMList1 = new MList();

        mTMList1.ID = "A";

        mTMList1.NAME = "变速箱种类";

        info.dmLists.add(mDMList1);

        info.tmLists.add(mTMList1);

        //排量列表
        if(dMlist!=null){
            for (int i=0;i<dMlist.length();i++){

                JSONObject object_dm = dMlist.optJSONObject(i);

                MList mDMList = new MList();

                mDMList.ID = object_dm.optString("id");

                mDMList.NAME = object_dm.optString("name");

                info.dmLists.add(mDMList);
            }
        }else{

            TOAST = "未能获取车辆型号信息，请稍后重试";

        }

        //档位列表
        if(tMlist!=null){
            for (int i=0;i<tMlist.length();i++){

                JSONObject object_tm = tMlist.optJSONObject(i);

                MList mTMList = new MList();

                mTMList.ID = object_tm.optString("id");

                mTMList.NAME = object_tm.optString("name");

                info.tmLists.add(mTMList);
            }
        }else{

            TOAST = "未能获取车辆型号信息，请稍后重试";

        }

        //车型列表
        if(cMlist!=null){
            for (int i=0;i<cMlist.length();i++){

                JSONObject object_cm = cMlist.optJSONObject(i);

                CMList mList = new CMList();

                mList.ID = object_cm.optString("id");

                mList.BRAND = object_cm.optString("brand");

                mList.SERIES = object_cm.optString("series");

                mList.DISPLACEMENTID = object_cm.optString("displacementId");

                mList.DISPLACEMENT = object_cm.optString("displacement");

                mList.TRANSMISSIONID = object_cm.optString("transmissionId");

                mList.TRANSMISSION = object_cm.optString("transmission");

                mList.MODELYEAR = object_cm.optString("modelYear");

                mList.NAME = object_cm.optString("name");

                mList.FINLETWAY = object_cm.optString("finletWay");

                info.cmLists.add(mList);
            }
        }else{

            TOAST = "未能获取车辆型号信息，请稍后重试";

        }
        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public List<MList> dmLists = new ArrayList<>();
        public List<MList> tmLists = new ArrayList<>();
        public List<CMList> cmLists = new ArrayList<>();

    }

    public static class MList implements Serializable{
        public String  ID,NAME;
    }



    public static class CMList implements Serializable{
                    //车型id 品牌名称 车系id  排量id         排量名称     档位id          档位名称     年款      车型详细 加油型号
        public String  ID,   BRAND,   SERIES, DISPLACEMENTID,DISPLACEMENT,TRANSMISSIONID ,TRANSMISSION ,MODELYEAR ,NAME , FINLETWAY;

    }




}
